﻿CREATE TABLE [Lunch].[Events] (
    [EventId]          INT           IDENTITY (1, 1) NOT NULL,
    [GuestId]          INT           NOT NULL,
    [EventName]        NVARCHAR (50) NOT NULL,
    [EventDate]        DATETIME2 (0) NOT NULL,
    [CreatedDateTime]  DATETIME      CONSTRAINT [DF_Events_CreatedDateTime] DEFAULT (getdate()) NOT NULL,
    [CreatedUserId]    VARCHAR (50)  CONSTRAINT [DF_Events_CreatedUserId] DEFAULT (user_name()) NOT NULL,
    [ModifiedDateTime] DATETIME      CONSTRAINT [DF_Events_ModifiedDateTime] DEFAULT (getdate()) NOT NULL,
    [ModifiedUserId]   VARCHAR (50)  CONSTRAINT [DF_Events_ModifiedUserId] DEFAULT (user_name()) NOT NULL,
    CONSTRAINT [PK_Events] PRIMARY KEY CLUSTERED ([EventId] ASC),
    CONSTRAINT [FK_Events_Guests] FOREIGN KEY ([GuestId]) REFERENCES [Lunch].[Guests] ([GuestId])
);


GO
CREATE NONCLUSTERED INDEX [IX_Events]
    ON [Lunch].[Events]([GuestId] ASC, [EventId] ASC);

